#ifndef SARRAY_HPP
#define SARRAY_HPP

#include <stddef.h>
#include <cassert>

template<typename T>
class SArray {
public:
	explicit SArray (size_t s) : storage(new T[s]), storage_size(s) {
		init();
	}
	//* copy constructor
	SArray(SArray<T> const& orig) : storage(new T[orig.size()]), storage_size(orig.size()) {
		copy();
	}
	//* assignment operator
	SArray<T>& operator= (SArray<T> const & orig) {
		if(&orig!=this) {
			copy(orig);
		}
		return *this;
	}
	//* destructor
	~SArray() { delete[] storage; }

	//size
	size_t size() const { return storage_size; }
	//index operator 
	T operator[] (size_t idx) const { return storage[idx]; }
	T& operator[](size_t idx) { return storage[idx]; }

	
protected:
	void init() {
		for (size_t idx=0; idx<size(); ++idx)
			storage[idx]=T();
	}
	void copy(SArray<T> const& orig) {
		assert(size()==orig.size());
		for (size_t idx=0; idx<size(); ++idx)
			storage[idx]=orig.storage[idx];
	}
private:
	T* storage; 
	size_t storage_size;
};

#endif